package com.icas.util.md5;

import com.icas.util.Constant;
import org.apache.shiro.crypto.hash.Md5Hash;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;


/**
 * @Author: tocchen
 * @Date: 2022/4/3 16:05
 * @Description:
 **/
public class PasswordRules {

    /**
     * 通过MD5+Hash散列+加密盐，生成密码
     * @param password 密码
     * @return 返回List集合，长度为2，[加密盐，生成的密码]
     */
    public static List  genPassword(String password){
        List<String> result = new ArrayList<>();
        String salt = SaltUtils.getSalt(new Random().nextInt(Constant.END_SALT_NUM) + Constant.START_SALT_NUM);
        Md5Hash md5Hash = new Md5Hash(password,salt,Constant.HASH_NUM);
        result.add(salt);
        result.add(md5Hash.toHex());
        return result;
    }

}
